#include "GenericSettingsDlg.h"
#include <wx/xrc/xmlres.h>
#include <wx/config.h>
#include "AppConfig.h"

BEGIN_EVENT_TABLE(GenericSettingsDlg, wxDialog)
    EVT_BUTTON(wxID_OK, GenericSettingsDlg::OnApply)
END_EVENT_TABLE()

GenericSettingsDlg::GenericSettingsDlg(wxWindow* parent) : chk_overwrite(NULL)
{
    wxXmlResource::Get()->LoadDialog(this, parent, "generic_settings_dlg");
    //SetClientSize(800, 600);
    LoadGenericConfig();
    InitUI();
}

GenericSettingsDlg::~GenericSettingsDlg()
{
    //dtor
}

void GenericSettingsDlg::InitUI()
{
    chk_overwrite = XRCCTRL(*this, "chk_overwrite_output", wxCheckBox);
    chk_showautocmds = XRCCTRL(*this, "chk_show_autocmds", wxCheckBox);

    if(chk_overwrite != NULL)
    {
        chk_overwrite->SetValue(overwrite_output);
    }
    if(chk_showautocmds != NULL)
    {
        chk_showautocmds->SetValue(show_autocmds);
    }
}

bool GenericSettingsDlg::LoadGenericConfig()
{
    AppConfig& config = AppConfig::Get();
    overwrite_output = config.IsOverwriteOutputfile();
    show_autocmds = config.IsShowAutocmds();
    return true;
}

void GenericSettingsDlg::OnApply(wxCommandEvent& event)
{
    AppConfig& config = AppConfig::Get();
    if(chk_overwrite != NULL)
    {
        config.SetOverwriteOutputfile(chk_overwrite->GetValue());
    }
    if(chk_showautocmds != NULL)
    {
        config.ShowAutocmds(chk_showautocmds->GetValue());
    }
    config.SaveGenericConfig();

    EndDialog(wxID_OK);
}
